package com.project.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private IEmployeeMapper emMapper;

    @Autowired
    private IDeptMapper deptMapper;


    @Override
    public void add(EmployeeBean employeeBean) {
        emMapper.insert(employeeBean);
    }

    @Override
    public IPage<EmployeeBean> findByItem(Integer pageNO, String deptName, String name) {

        return emMapper.findByItem(new Page(pageNO,3),deptName,name);
    }

    @Override
    public EmployeeBean findById(Integer id) {
        EmployeeBean employeeBean = emMapper.selectById(id);
        employeeBean.setDept(deptMapper.selectById(employeeBean.getDeptId()));

        return employeeBean;
    }
}
